from apps.mlplatform.models.task import Task
from django.utils import timezone
from apps.mlplatform.ml_handle.utils import get_train_model, get_result_and_imgs, get_prediction_model


def handle_ml(task: Task):
    if task.task_type == 0:
        task.start_time = timezone.now()
        task.status = 1
        task.save()
        clf = get_train_model(task.algorithm, task.params)
        abs_file_path = task.get_abs_file_path()
        result, imgs = get_result_and_imgs(clf, task, abs_file_path)
        task.result = result
        task.visual_pic = imgs
        task.end_time = timezone.now()
        task.status = 2
        task.save()
        return {'result': result, 'imgs': imgs}
    else:
        clf = get_prediction_model(task.algorithm)


def handle_visual_recognition():
    '''

    :return:
    '''
    pass


if __name__ == '__main__':
    # file = 'test.xlsx'
    # data = read_dataset(file)
    # get_x_y_data(data)
    clf = get_train_model('SVM', {})
    print(clf)
